#pragma once
#include <vector>
#include "SharedPtr.h"
class VertexFactory;
class Material;
class IndexData;

class Renderable
{
public:
	friend class Scene;
	enum { INVALID_SCENE_ID = -1 };

	class DrawListElementLink
	{
	public:
		virtual void Delete() = 0;
	};

	typedef SharedPtr<DrawListElementLink> DrawListElementLinkPtr;
	typedef std::vector<DrawListElementLinkPtr> DrawListElementLinkList;

public:
	Renderable();
	virtual ~Renderable();

	inline size_t getSceneID() const { return mSceneID; }

	inline int getRenderGroup() const { return mRenderGroup; }
	inline void setRenderGroup(int v) { mRenderGroup = v; }
	
	inline const Matrix& getWorldMatrix() const { return mWorldMatrix; }
	inline void setWorldMatrix(const Matrix& v) { mWorldMatrix = v; }

	virtual VertexFactory* getVertexFactory() = 0;
	virtual MaterialInstance* getMaterial() = 0;
	virtual const IndexData* getIndexData() const { return NULL; }

	void AddToScene(Scene* scene);
	void RemoveFromScene(Scene* scene);

	void UpdateSceneID(size_t id);

	void Link(DrawListElementLinkPtr& link);
	void Unlink(DrawListElementLinkPtr& link);

	virtual size_t GetGpuSkinMatrix(Matrix3x4* xform) const { return 0; }

private:
	mutable size_t mSceneID;
	int mRenderGroup;
	Matrix mWorldMatrix;
	DrawListElementLinkList mLinkList;
	
	inline void setSceneID(size_t v) const { mSceneID = v; }
};

inline void Renderable::Link(Renderable::DrawListElementLinkPtr& link)
{
	mLinkList.push_back(link);
}

inline void Renderable::Unlink(Renderable::DrawListElementLinkPtr& link)
{
	//mLinkList.push_back(link);
}